package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.Cargo;

import java.util.List;

public class GetCargo implements Command {
    // get cargo by id <id>
    // get cargo by name <name>
    @Override
    public void execute( String[] args ) {
        if (args.length != 5 || !args[2].equals("by"))
            throw new IllegalArgumentException();
        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        if (args[3].equals("id")) {
            Long id = Long.parseLong(args[4]);
            Cargo cargo = manager.getCargoById(id);
            System.out.println("Id\tName\tWeight");
            System.out.println(cargo.getId() + "\t" + cargo.getName() + "\t" + cargo.getWeight());
        } else if (args[3].equals("name")) {
            List<Cargo> cargos = manager.getCargosWithName(args[4]);
            System.out.println("Id\tName\tWeight");
            for (int i = 0; i < cargos.size(); i++)
                System.out.println(cargos.get(i).getId() + "\t" + cargos.get(i).getName() + "\t" + cargos.get(i).getWeight());
        } else
            throw new IllegalArgumentException();
    }
}
